package org.example;

import java.util.Stack;

//leetcode 20 有效的括号 https://leetcode.cn/problems/valid-parentheses/description/
public class Test3 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()) {
            if (c == '(' || c == '{' || c == '[') {
                stack.add(c);
            }else {
                if (stack.empty()) return false;
                char t = stack.pop();
                if ((c == ')' && t != '(') || (c == '}' && t != '{') || (c == ']' && t != '[')) {
                    return false;
                }
            }
        }
        return stack.empty();
    }

    public static void main(String[] args) {
        Test3 test3 = new Test3();
        test3.isValid("()[]{}");
        System.out.println(666);
    }
}
